package me.illtamer.rpc.hook;

import lombok.extern.slf4j.Slf4j;
import me.illtamer.rpc.factory.ThreadPoolFactory;
import me.illtamer.rpc.util.NacosUtil;

@Slf4j
public class ShutdownHook {
    // 单例创建
    public static final ShutdownHook SHUTDOWN_HOOK = new ShutdownHook();

    /**
     * 注销服务的钩子
     * */
    public void addClearAllHook() {
        log.info("服务端关闭前将自动注销所有服务");
        Runtime.getRuntime().addShutdownHook(new Thread(() -> {
            NacosUtil.clearRegistry();
            ThreadPoolFactory.shutDownAll();
        }));
    }

}
